package com.vietnam.power.persistence;

import java.io.Serializable;
import java.util.Date;
import java.util.List;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

import com.vietnam.power.dao.IAuditUpdateTable;


/**
 * The persistent class for the location database table.
 * 
 */
@Entity
@Table(name="location")
public class Location implements Serializable, IAuditUpdateTable {
	private static final long serialVersionUID = 1L;
	private Long locationId;
	private Date createdDate;
	private String locationName;
	private Date updatedDate;
	private UserInfo createdBy;
	private UserInfo updatedBy;
	private List<Product> products;

	public Location() {
	}


	@Id
	@GeneratedValue(strategy=GenerationType.AUTO)
	@Column(name="LOCATION_ID")
	public Long getLocationId() {
		return this.locationId;
	}

	public void setLocationId(Long locationId) {
		this.locationId = locationId;
	}


	@Temporal(TemporalType.TIMESTAMP)
	@Column(name="CREATED_DATE")
	public Date getCreatedDate() {
		return this.createdDate;
	}

	public void setCreatedDate(Date createdDate) {
		this.createdDate = createdDate;
	}


	@Column(name="LOCATION_NAME")
	public String getLocationName() {
		return this.locationName;
	}

	public void setLocationName(String locationName) {
		this.locationName = locationName;
	}


	@Temporal(TemporalType.TIMESTAMP)
	@Column(name="UPDATED_DATE")
	public Date getUpdatedDate() {
		return this.updatedDate;
	}

	public void setUpdatedDate(Date updatedDate) {
		this.updatedDate = updatedDate;
	}

	//bi-directional many-to-one association to Product
	@OneToMany(mappedBy="location")
	public List<Product> getProducts() {
		return this.products;
	}

	public void setProducts(List<Product> products) {
		this.products = products;
	}

	public Product addProduct(Product product) {
		getProducts().add(product);
		product.setLocation(this);

		return product;
	}

	public Product removeProduct(Product product) {
		getProducts().remove(product);
		product.setLocation(null);

		return product;
	}


	@Override
	@ManyToOne(fetch=FetchType.LAZY)
	@JoinColumn(name="CREATED_BY")
	public UserInfo getCreatedBy() {
		return this.createdBy;
	}


	@Override
	public void setCreatedBy(UserInfo createdBy) {
		this.createdBy = createdBy;		
	}


	@Override
	@ManyToOne(fetch=FetchType.LAZY)
	@JoinColumn(name="UPDATED_BY")
	public UserInfo getUpdatedBy() {
		return this.updatedBy;
	}


	@Override
	public void setUpdatedBy(UserInfo updatedBy) {
		this.updatedBy = updatedBy;
	}

}